package hc.bre.log

import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.data.mongodb.MongoDatabaseFactory
import org.springframework.data.mongodb.core.MongoTemplate

import java.util.concurrent.CompletableFuture

class MongoLogStore extends LogStore{
	protected static final Logger _log = LoggerFactory.getLogger(MongoLogStore);
	
	MongoTemplate mongoTemplate

	public MongoLogStore(MongoDatabaseFactory mongoFactory) {
		//mongoFactory = new SimpleMongoClientDatabaseFactory("mongodb://jmserver:27017/ruledb");
		mongoTemplate= new MongoTemplate(mongoFactory)
	}

	@Override
	public void save(RootRuleLog rulelog) {
		CompletableFuture.runAsync({
			try {
				mongoTemplate.insert(rulelog);
			}
			catch(Throwable ex) {
				_log.error ("Exception is throwed while saving rule log.\n",ex);
			};
		});
		
	}
}
